﻿Namespace Sigortali.SaglikKarnesi
	Module Functions

		Sub Kaydet(ByVal Process As Token, ByVal sno As Integer, ByVal kimlik As String, ByVal tur As Integer, ByVal bastar As Date, ByVal bittar As Date, ByVal kaykul As String)
			Process.Save("ssd.dbo.skarne", "sno,kimlik,tur,bastar,bittar,kaykul", sno, kimlik, tur, bastar, bittar, kaykul)
		End Sub

		Function KarneListesi(ByVal Process As Token, ByVal sno As String, ByVal Tarih1 As Date, ByVal Tarih2 As Date) As Recordset
			Q("select *")
			Q("from (select sno,kimlik,tur,bastar,bittar,islemtar,kaykul from ssd..skarne")
			Q("union all select sno,kimlik,case skarneturu when 'A' then 0 when 'B' then 1 end, skarnebastar,skarnesontar,islemtar,kaykul from ssd..skarneab")
			Q("union all select distinct sno,kimlik,case skarneturu when 'A' then 2 when 'B' then 3 end, gyskarbastar,gyskarsontar,islemtar,kaykul from ssd..sgyskarne) t")
			Q("where 1=1")
			If sno <> "" Then Q("and sno = " & sno)
			Q("and islemtar between :a and :b")
			Q("order by islemtar desc,kimlik")
			Return Process.OpenSQL("*", Tarih1, Tarih2.AddDays(1))
		End Function

		Function ProblemliYatirimKontroluKimlik(ByVal Process As Token, ByVal sno As String, ByVal Tarih As Date) As Boolean
			Dim Rs As Recordset = Sigortali.SnoAra(Process, sno)
			If Not Process.OpenSQL("select * from ssd..sheskp where bordrotar >= :tarih and kimlik = :~kimlik", Tarih, Rs("kimlik")).EOF Then Return True
			Return False
		End Function

		Function ProblemliYatirimKontroluIsim(ByVal Process As Token, ByVal sno As String, ByVal Tarih As Date) As Boolean
			Dim Rs As Recordset = Sigortali.SnoAra(Process, sno)
			If Not Process.OpenSQL("select * from ssd..sheskp where bordrotar >= :tarih and adi like :~adi + '%' and soyadi like :~soyadi + '%'", Tarih, Rs("adi"), Rs("soyadi")).EOF Then Return True
			Return False
		End Function

	End Module
End Namespace
